package com.tg.app.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.demo.view.SettingItemTextViewEx;
import com.tg.app.R;
import com.tg.data.bean.TrackBean;
import com.tg.appcommon.android.ResourcesUtil;
import com.tange.base.toolkit.StringUtils;

import java.util.List;

public class CruiseItemAdapter extends BaseAdapter {
    private List<TrackBean> list;

    private Context context;

    private PrePositionAdapter.PrePositionListener prePositionListener;
    public void setPrePositionListener(PrePositionAdapter.PrePositionListener listener){
        this.prePositionListener = listener;
    }
    public CruiseItemAdapter(List<TrackBean> list, Context context){
        this.list = list;
        this.context = context;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }



    @SuppressLint("InflateParams")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TrackBean data = list.get(position);
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(data.track == 0? R.layout.layout_item_criuse : R.layout.layout_item_criuse_view, null);
        }

        SettingItemTextViewEx settingItemTextView = (SettingItemTextViewEx)convertView;

        String name = data.name;
        if (StringUtils.isEmpty(data.name)){
            name = ResourcesUtil.getString(R.string.cruise) + data.track_no;
        }
        settingItemTextView.setName(name);
        if (data.track == 1){
            settingItemTextView.setRightArrow(R.drawable.ic_tange_line_scan);
        }else if (data.track == 2){
            settingItemTextView.setRightArrow(R.drawable.cruise);
        }
        settingItemTextView.getRightArrow().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (prePositionListener != null){
                    prePositionListener.click(position);
                }
            }
        });





        return convertView;
    }
}
